package com.web.dao.impl;

import com.web.dao.UserDAO;
import com.web.entity.User;
import com.web.util.JDBCUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户数据访问接口实现类
 */
@Repository
public class UserDAOImpl implements UserDAO {

    /**
     * 通过用户名查询用户
     * @param username
     * @return
     */
    @Override
    public User selectUserByUsername(String username) {
        List<User> users = JDBCUtils.query(User.class,
                "select * from t_user where username = ?",username);
        if(users.size() > 0){
            return users.get(0);
        }
        return null;
    }

    @Override
    public void updateUser(User user) {
        JDBCUtils.update("update t_user set nickname=?,icon=?,email=? where id=?",
                user.getNickname(),user.getIcon(),user.getEmail(),user.getId());
    }
}
